function hfile = aft_SetHandle(hfile, hname, hvalue)
% AFT::SetHandle  - method for any BVQXfile type
%
% FORMAT:       [obj = ] obj.SetHandle(hname, hvalue);
%
% Input fields:
%
%       hname       handle name (valid identifier ~= 'BVQXfile')
%       hvalue      handle value
%
% Output fields:
%
%       obj         altered object
%
% TYPES: ALL
%
% Note: not valid for the root object.

% Version:  v0.8a
% Build:    9102122
% Date:     Oct-21 2008, 10:09 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% only valid for single file
if nargin < 3 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, true) || ...
    hfile.L == 0 || ...
   ~ischar(hname) || ...
   ~isrealvarname(hname(:)') || ...
    strcmpi(hname(:)', 'bvqxfile')
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end

% set handles
try
    sc = bvqxfile_getscont(hfile.L);
    sc.H.(hname(:)') = hvalue;
    bvqxfile_setscont(hfile.L, sc);
catch
    % do nothing
end
